//
//  HCHotStoreView.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/2/8.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCHotStoreView.h"

#import "HCHotStoreTableViewCell.h"

#import "HCFindHotStoreModel.h"

@interface HCHotStoreView () <UITableViewDataSource,UITableViewDelegate> {
    UITableView *tableView_;
    HCFindHotStoreModel *model_;
}

@end

@implementation HCHotStoreView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initializeSubView:frame];
    }
    return self;
}

-(void)initializeSubView:(CGRect)frame {
    
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:frame];
    bgImageView.userInteractionEnabled = YES;
    bgImageView.image = [UIImage imageNamed:@"happy_hotstore_bg"];
    [self addSubview:bgImageView];
    
    UIView *topBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, YBKAdaptiveH(105))];
    topBG.backgroundColor = [UIColor clearColor];
    [self addSubview:topBG];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, (YBKAdaptiveH(105) - 35)/2.0, 200, 35)];
    label.textColor = [UIColor whiteColor];
    label.text = @"门店热榜";
    label.font = [UIFont boldSystemFontOfSize:30];
    [topBG addSubview:label];
    
    
    tableView_ = [[UITableView alloc] initWithFrame:CGRectMake(10, topBG.frame.origin.y+topBG.frame.size.height, frame.size.width - 20, frame.size.height - topBG.frame.size.height)];
    tableView_.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView_.delegate = self;
    tableView_.dataSource = self;
    tableView_.backgroundColor = [UIColor clearColor];
    tableView_.showsVerticalScrollIndicator = NO;
    tableView_.rowHeight = YBKAdaptiveH(360);
    [self addSubview:tableView_];
    
    [tableView_ registerNib:[UINib nibWithNibName:@"HCHotStoreTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"hotstore"];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (model_) {
        return model_.f_hot.count;
    }else{
        return 0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HCHotStoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"hotstore" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    
    if (model_) {
        HCFindHotStoreData *data = model_.f_hot[indexPath.row];
        cell.model = data;
    }
    cell.topLabel.text = [NSString stringWithFormat:@"TOP %ld",(indexPath.row + 1)];
    
    return cell;
}

-(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

-(void)setModel:(id)model {
    model_ = (HCFindHotStoreModel *)model;
    [tableView_ reloadData];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
